<?php $this->_extends('../_layouts/default_layout');?>
<?php $this->_block('contents');?>
<script src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript">
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	var product_categories_data = <?=$product_categories?>;
	$(document).mselect(product_categories_data, 'product_categories_id', 'product_categories_id', "<?=isset($_GET['product_categories_id']) ? $_GET['product_categories_id'] : 0?>");
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get" id="sales_report_form">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>出库时间</th>
	<td>
		<input type="text" class="datepicker" name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : ''?>" /> to
		<input type="text" class="datepicker" name="end_shipped_time" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>产品分类</th>
	<td><input type="hidden" id="product_categories_id" name="product_categories_id" /></td>
</tr>
<tr>
	<th></th>
	<td>
		<input type="hidden" name="is_search" value="1" />
		<input type="submit" class="button" value="查询" />
	</td>
</tr>
</table>
</form>
</fieldset>
<?if (isset($_GET['is_search']) && $_GET['is_search'] == 1):?>
<table class="list_table" width="50%">
<tr>
	<th>店铺名</th>
	<th>产品成本</th>
	<th>产品成本占率</th>
	<th>销售金额</th>
	<th>销售金额占率</th>
</tr>
<?foreach ($report as $r):?>
<tr>
	<td><?=$r['shop_name']?></td>
	<td><?=sprintf('%.2f', $r['product_amount'])?></td>
	<td><?=empty($total_product_amount) ? '0' : sprintf('%.2f', $r['product_amount'] / $total_product_amount * 100)?>%</td>
	<td><?=sprintf('%.2f', $r['sales_amount'])?></td>
	<td><?=empty($total_sales_amount) ? '0' : sprintf('%.2f', $r['sales_amount'] / $total_sales_amount * 100)?>%</td>
</tr>
<?endforeach;?>
<tr>
	<th>合计</th>
	<td><?=sprintf('%.2f', $total_product_amount)?></td>
	<td></td>
	<td><?=sprintf('%.2f', $total_sales_amount)?></td>
	<td></td>
</tr>
</table>
<?endif;?>
<?php $this->_endblock();?>